package learn_effective_java.item_02.nutritionfacts;

import learn_effective_java.item_02.nutritionfacts.NutritionFacts3.Builder;

public class Client {
	public static void main(String[] args) {
		/*
		 * The NutritionFacts class is immutable, 
		 * and all parameter default values are in one place.
		 * The builder's setter methods return the builder itself 
		 * so that invocations can be chained, resulting in a fluent API.
		 * Here's how the client code looks:
		 */
		Builder builder = new NutritionFacts3.Builder(240, 8)
				.calories(100).sodium(35).carbohydrate(27);
		NutritionFacts3 cocaCola = builder
				.build();
//		builder.calories(0);
//		cocaCola
		System.out.println(cocaCola);
	}
}
/*
 * This client code is easy to write and, more importantly, 
 * easy to read.
 * The Builder pattern simulates named optional parameters as found in Python and Scala.
 * 
 * Validity checks were omitted for brevity.
 * To Detect invalid parameters as soon as possible,
 * check parameter validity in the builder's constructor 
 * and methods.
 * 
 * To ensure these invariants against attack, do the checks on object fields 
 * after copying parameters from the builder.
 * If a check fails, throw an IllegalArgumentException whose detail message 
 * indicates which parameters are invalid.
 * 
 * 
 */